﻿@{
    ViewBag.Title = "RetrieveAllProduct";
    Layout = "~/Areas/Admin/Views/Shared/_Admin.cshtml";
}

<div class="row-fluid">
    <h3 class="header smaller lighter blue">Tìm kiếm sản phẩm</h3>
    <div class="widget-box">
        <div class="widget-header widget-header-small">
            <h5 class="lighter">Tìm kiếm sản phẩm 
                
            </h5>
        </div>
        <div class="widget-body">
            <div class="widget-main">
                Tìm theo danh mục: 
                <select id="slFind" onchange="findProducts();">
                    <option value="1">Đồ gia dụng</option>
                    <option value="2">Đồ điện tử</option>
                    <option value="3">Đồ điện lạnh</option>
                </select>
                @*&nbsp; &nbsp;
                Tìm theo mã sản phẩm
                <input type="text" placeholder="Nhập mã sp và nhấn enter" onchange="retrieveProductById(this)" />
                *@
            </div>
        </div>
    </div>

    @{
        List<EC18_ESHOP.Models.PRODUCT> arrProduct = ViewBag.arrProduct;
        if (arrProduct.Count > 0)
        {
        <script type="text/javascript">
            var cbb = document.getElementById('slFind');
            cbb.selectedIndex = 3;
        </script>
        }
    }

    <h3 class="header smaller lighter blue">Danh sách các sản phẩm</h3>
    <div class="table-header">
        @{if (ViewBag.selected != null)
          {
            @ViewBag.selected
          }         
        }
    </div>

    <table id="sample-table-2" class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th>Mã sản phẩm</th>
                <th>Tên sản phẩm</th>
                <th class="hidden-480">Giá bán</th>
                <th class="hidden-480">Nhà sản xuất</th>
                <th class="hidden-480">Trạng thái</th>
                <th>Xử lí</th>
            </tr>
        </thead>

        <tbody>
            @{
                foreach (EC18_ESHOP.Models.PRODUCT item in arrProduct)
                {<tr>
                    <td>
                        <a href="#">@item.ProductId</a>
                    </td>
                    <td>@item.ProductName</td>
                    <td class="hidden-480">@item.ProductPrice</td>
                    <td class="hidden-phone">@item.MANUFACTURER.ManufacturerName</td>

                    @{if (item.Status)
                      {
                        <td class="hidden-480">Enable
                            <input type="radio" checked name="@item.Product_ID" value="enable" onchange="handleProduct(this)" />
                            &nbsp;&nbsp
                            Disable
                            <input type="radio" name="@item.Product_ID" value="disable" onchange="handleProduct(this)" />
                        </td>
                      }
                      else
                      {
                        <td class="hidden-480">Enable
                            <input type="radio" name="@item.Product_ID" value="enable" onchange="handleProduct(this)" />
                            &nbsp;&nbsp
                            Disable
                            <input type="radio" checked name="@item.Product_ID" value="disable" onchange="handleProduct(this)" />
                        </td>
                      }
                    }
                    <td class="td-actions">
                        <div class="hidden-phone visible-desktop action-buttons">
                            <a class="green" href="~/Admin/AdminHome/UpdateProduct/?productId=@item.Product_ID">
                                <i class="icon-pencil bigger-130"></i>
                            </a>
                        </div>

                        <div class="hidden-desktop visible-phone">
                            <div class="inline position-relative">
                                <ul class="dropdown-menu dropdown-icon-only dropdown-yellow pull-right dropdown-caret dropdown-close">
                                    <li>
                                        <a href="#" class="tooltip-success" data-rel="tooltip" title="Edit">
                                            <span class="green">
                                                <i class="icon-edit bigger-120"></i>
                                            </span>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </td>
                </tr>
                }

            }

        </tbody>
    </table>
    @*<div class="row-fluid">
        <div class="span6">
            <div id="sample-table-2_info" class="dataTables_info">Showing 1 to 10 of 23 entries</div>
        </div>
        <div class="span6">
            <div class="dataTables_paginate paging_bootstrap pagination">
                <ul>
                    <li class="prev disabled"><a href="#"><i class="icon-double-angle-left"></i></a></li>
                    <li class="active"><a href="#">1</a></li>
                    <li><a href="#">2</a></li>
                    <li><a href="#">3</a></li>
                    <li class="next"><a href="#"><i class="icon-double-angle-right"></i></a></li>
                </ul>
            </div>
        </div>
    </div>*@
</div>

<script type="text/javascript">
    function findProducts() {
        var val = { val: document.getElementById('slFind').value };
        $.post('/Admin/AdminHome/retrieveAllProduct/', val, function (data) {
            //location.replace("retrieveAllProduct/?val=" + document.getElementById('slFind').value);
            location.replace("?val=" + document.getElementById('slFind').value);
        });
    }

    function handleProduct(myRadio) {
        var val = { productId: myRadio.name };
        var value = myRadio.value;
        if (value == "enable") {
            $.post('/Admin/AdminHome/enableProduct/', val, function (data) {

            });
        }
        if (value == "disable") {
            $.post('/Admin/AdminHome/disableProduct/', val, function (data) {
                
            });
        }
    }
</script>
